#include "QtUI/SaveProjectCommand.qth"
#include "QtUI/SaveProjectCommand.moh"
#include "Model/Project.hpp"
#include "Storage/ProjectStorage.hpp"
#include "Storage/PackageStorage.hpp"
#include "Storage/RequirementsStorage.hpp"
#include "Storage/StorageFactory.hpp"
#include "Storage/StorageError.hpp"
#include "Ctrl/ControlCenter.hpp"
#include "Ctrl/ProjectController.hpp"
#include <QtGui/QMessageBox>

namespace QtUI
{

// ---------------------------------------------------------------------------------------------------------------------

SaveProjectCommand::SaveProjectCommand( QAction* pBoundAction)
	: UICommandBase( pBoundAction)
	, Impl::ProjectRelatedCommandEnabler( pBoundAction)
{
}

// ---------------------------------------------------------------------------------------------------------------------

bool SaveProjectCommand::execute( bool /*checked*/ /*= false*/)
{
	try
	{
		Ctrl::ControlCenter::instance().prjController().storageFactory().getProjectStorage().store();
		Ctrl::ControlCenter::instance().prjController().storageFactory().getPackageStorage().store();
		Ctrl::ControlCenter::instance().prjController().storageFactory().getRequirementStorage().store();
		return true;
	}
	catch( Storage::StorageError& err)
	{
		QMessageBox::critical( NULL, tr( "Project failed to save. Reason:\n") + QString( err.what()), tr("Saving Project"));
		return false;
	}
}

} // namespace QtUI
